class Solution(object):
    def isRobotBounded(self, instructions):
        now = (0, 0)
        state = 0
        a_set = {(0, 0)}
        for _ in range(4):
            for c in instructions:
                if c == 'R':
                    state = (state + 1) % 4
                if c == 'L':
                    state = (state - 1) % 4
                if c == 'G':
                    if state == 0:
                        v = (now[0], now[1] + 1)
                    if state == 1:
                        v = (now[0] + 1, now[1])
                    if state == 2:
                        v = (now[0], now[1] - 1)
                    if state == 3:
                        v = (now[0] - 1, now[1])
                    a_set.add(v)
                    now = v
        for c in instructions:
            if c == 'R':
                state = (state + 1) % 4
            if c == 'L':
                state = (state - 1) % 4
            if c == 'G':
                if state == 0:
                    v = (now[0], now[1] + 1)
                if state == 1:
                    v = (now[0] + 1, now[1])
                if state == 2:
                    v = (now[0], now[1] - 1)
                if state == 3:
                    v = (now[0] - 1, now[1])
                if v not in a_set:
                    return False
                now = v
        return True


data = Solution()
instructinos = "GLRLLGLL"
print(data.isRobotBounded(instructinos))
